#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n,r;
    cin>>n>>r;
    int* nums=new int[n];
    for (int i=0;i<n;i++)
    {
        cin>>nums[i];
    }
    if (r+r<n)
    {
        sort(nums+r,nums+n-r);
    }
    for (int i=0;i<n;i++)
    {
        if (i==0)
            cout<<nums[i];
        else
            cout<<" "<<nums[i];
    }
}